package cn.huiyunche.driver.datasync.controller;

import cn.huiyunche.base.service.interfaces.DWaybillService;
import cn.huiyunche.base.service.interfaces.SUserService;
import cn.huiyunche.base.service.interfaces.UserService;
import cn.huiyunche.base.service.model.DWaybill;
import cn.huiyunche.base.service.model.SUser;
import cn.huiyunche.base.service.vo.Result;
import cn.huiyunche.base.service.vo.TmsQueueDriverVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/tmsOrderSync")
public class TmsOrderSyncController {

    @Autowired
    private DWaybillService dWaybillService= null;

    @Autowired
    private UserService userService;

    private final static String domainName="ULC/ZC.";
    /**
     * 订单指令推送tms
     * @return
     **/
    @RequestMapping(value = "/orderToTms", method = RequestMethod.GET)
    public
    @ResponseBody
    Result<Object> accountingPrice(@RequestParam("orderCode")String orderCodes) {
        Result<Object> result = new Result<>(true, "推送成功");
        try {
            String[] split = orderCodes.split(",");
            for (String orderCode : split) {
                DWaybill waybill = dWaybillService.getByTmsOrderCode(orderCode.trim().replace("\n", ""));
                SUser user = userService.getById(waybill.getUserId());
                TmsQueueDriverVo tmsQueueDriverVo=new TmsQueueDriverVo();
                tmsQueueDriverVo.setPhone(user.getPhone());
                dWaybillService.DistributionOrderToTms(tmsQueueDriverVo,waybill.getOrderLineId());
            }
        } catch (Exception e) {
            result.setMessage(e.getMessage());
        }
        return result;
    }
}
